import { vpost, vlink } from '@api'
import { coinList } from './frontShow'
class LoadSetting {
	constructor(self) {
		this.self = self
		this.lang()
		this.signed()
		this.api_coinList()
	}
	_commit(w, t) {
		let self = this.self
		self.$store.commit('set_' + w, t)
	}
	lang() {
		let l = sessionStorage.lang || 'cn'
		this._commit('lang', l)
	}
	signed() {
		if (sessionStorage.signed === '1') {
			this._commit('user_signed', true)
			this._commit('user_name', sessionStorage.name)
			this._commit('user_uid', sessionStorage.uid)
		}
	}
	async api_coinList() {
		let re = []
		let comin = []
		if (window.fronting) {
			comin = coinList
		}
		// todo 这个接口是不是有问题
		await vpost('real/indexmarket.html', { symbol: 1 }).then(re => {
			comin.push({
				change: re.rose + '%',
				c2c: 'LIFE/BTC',
				price: re.price,
				max: re.buy,
				min: re.sell,
			})
		})
		// await vpost('real/indexmarket.html', {symbol: 1}).then(re => {
		// 	comin.push({
		// 		change: re.rose + '%',
		// 		c2c: 'shuncheng/eth',
		// 		price: re.price,
		// 		max: re.buy,
		// 		min: re.sell,
		// 	})
		// })

		comin.forEach((v, index) => {
			v.color = 'coin-' + (v.change.match('-') ? 'green' : 'red')
			v.clas = v.c2c.match(/[A-Z]+$/)[0]
			v.cid = index
			v.marked = true
			re.push(v)
		})
		this._commit('api_coinList', re)
	
	}
}
export default LoadSetting
